<template>
	<view class="riddleItem">
		<navigator :url="navigateUrl" class="box">
			<view class="text-area">
				<text v-for="(line, index) in item.lines" :key="index" class="line-text">
					{{ line }}
				</text>
			</view>
			<view class="mask">{{ item.tag ? item.tag : item.lines[0].slice(0, 3) }}</view>
		</navigator>
	</view>
</template>

<script setup>
	import {
		computed
	} from 'vue';
	const props = defineProps({
		item: {
			type: Object,
			default: () => ({
				type: '',
				tag: '',
				lines: [],
				answer: '',
				index:1,
				aindex:1,
				articleId:''
			})
		}
	})

	const navigateUrl = computed(() => {
		let baseUrl = props.item.type === 'class' ? '/pages/classlist/classlist' : '/pages/play/play';
		let params = '';

		if (props.item.type === 'class' ) {
			let articleIdParam = `?articleId=${encodeURIComponent(props.item.articleId)}`;
			params += articleIdParam;
		}else{
			let articleIdParam = `?index=${props.item.index}&aindex=${props.item.aindex}&articleId=${props.item.articleId}`;
			params += articleIdParam;
		}

		return `${baseUrl}${params}`;
	});
	
</script>

<style lang="scss" scoped>
	.riddleItem {
		background-color: #f8f8f8;
		box-shadow: 0 2rpx 5rpx rgba(0, 0, 0, 0.10);
		border-radius: 10px;
		transition: all 0.3s cubic-bezier(.25, .8, .25, 1);

		.box {
			height: 340rpx;
			border-radius: 10rpx;
			overflow: hidden;
			position: relative;
			width: 100%;

			// 添加对文本的样式
			.text-area {
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				height: 100%;
				width: 100%;
				max-width: 90%;
				padding: 16rpx;

				.line-text {
					display: block;
					text-align: center;
					line-height: 1.2;
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
					max-width: 100%;
					color: #333333;
				}
			}

			.mask {
				width: 100%;
				position: absolute;
				bottom: 0;
				left: 0;
				background: rgba(0, 0, 0, 0.2);
				color: #fff;
				display: flex;
				align-items: center;
				justify-content: center;
				backdrop-filter: blur(20rpx);
				font-weight: 600;
				font-size: 30rpx;
			}
		}

		.box.more {
			.mask {
				width: 100%;
				height: 100%;
				flex-direction: column;

				.text {
					font-size: 26rpx;
				}
			}

		}
	}

	.riddleItem:hover {
		box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
	}
</style>